#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：python_learning 
@File ：validate_input.py
@IDE  ：PyCharm 
@Author ：李涵彬
@Date ：2024/6/4 下午3:29 
"""


def validate_input(*validations):
	def decorator(func):
		def wrapper(*args, **kwargs):
			for i, val in enumerate(args):
				if i < len(validations):
					if not validations[i](val):
						raise ValueError(f"Invalid argument: {val}")
			for key, val in kwargs.items():
				if key in validations[len(args):]:
					if not validations[len(args):][key](val):
						raise ValueError(f"Invalid argument: {key}={val}")
			return func(*args, **kwargs)

		return wrapper

	return decorator
